import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/user/main',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'user/main',
      component: () => import('@/views/dashboard/index')
    }]
  },
  {
    path: '/resource',
    component: Layout,
    redirect: '/resource/index',
    name: 'ResourceManage',
    meta: { title: '资源管理', icon: 'example' },
    children: [
      { path: 'index', name: 'Resource', meta: { title: '权限资源', icon: 'example' },
        component: () => import('@/views/resourceManage/treeResource')
      },
      { path: 'resource-permission/:resource_id', name: 'PermissionList', meta: { title: '权限列表', icon: 'example' },
        component: () => import('@/views/resourceManage/permissionList')
      }
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/manager',
    name: 'Example',
    meta: { title: '用户管理', icon: 'example' },
    children: [
      {
        path: 'manager',
        name: 'manager',
        component: () => import('@/views/userManager/index'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'role-list',
        name: 'RoleList',
        component: () => import('@/views/userManager/roleList'),
        meta: { title: '角色列表', icon: 'tree' }
      }
    ]
  },

  {
    path: '/dict',
    component: Layout,
    name: 'system',
    meta: { title: '系统管理', icon: 'form' },
    redirect: '/system/data-dictionary',
    children: [
      {
        path: 'dict',
        name: 'DataDictionary',
        component: () => import('@/views/systemManager/dataDictionary'),
        meta: { title: '数字字典', icon: 'form' }
      },
      {
        path: 'group',
        name: 'BusinessGroup',
        component: () => import('@/views/systemManager/businessGroup'),
        meta: { title: '业务分组', icon: 'form' }
      }
    ]
  },
  {
    path: '/log',
    component: Layout,
    name: 'system',
    meta: { },
    redirect: '/log/login-log',
    children: [
      {
        path: 'login-log',
        name: 'LoginLog',
        component: () => import('@/views/systemLog/loginLog'),
        meta: { }
      },
      {
        path: 'operate-log',
        name: 'OperateLog',
        component: () => import('@/views/systemLog/operateLog'),
        meta: { }
      },
      {
        path: 'exception-log',
        name: 'ExceptionLog',
        component: () => import('@/views/systemLog/exceptionLog'),
        meta: { }
      }
    ]
  },
  {
    path: '/organization',
    component: Layout,
    name: 'organization',
    meta: { },
    redirect: '/log/login-log',
    children: [
      {
        path: 'framework',
        name: 'Framework',
        component: () => import('@/views/organizationFramework/framework'),
        meta: { }
      },
      {
        path: 'employee-manage',
        name: 'EmployeeManage',
        component: () => import('@/views/organizationFramework/employeeManage'),
        meta: { }
      },
      {
        path: 'employee-info',
        name: 'EmployeeInfo',
        component: () => import('@/views/organizationFramework/employeeInfo'),
        meta: { }
      }
    ]
  },
  {
    path: '/address-book',
    component: Layout,
    name: 'Address',
    meta: {},
    children: [
      {
        path: 'index',
        name: 'AddressBook',
        component: () => import('@/views/organizationFramework/addressBook'),
        meta: { }
      }]
  },
  {
    path: '/schedule',
    component: Layout,
    name: 'schedule',
    meta: { title: '日程管理', icon: 'form' },
    redirect: '/schedule/schedule-list',
    children: [
      {
        path: 'schedule-list',
        name: 'ScheduleList',
        component: () => import('@/views/scheduleManage/scheduleList'),
        meta: { title: '日程列表', icon: 'form' }
      },
      {
        path: 'customGroup-list',
        name: 'CustomGroupList',
        component: () => import('@/views/scheduleManage/CustomGroupList'),
        meta: { title: '自定义组', icon: 'form' }
      },
      {
        path: 'maintain-attention',
        name: 'MaintainAttention',
        component: () => import('@/views/scheduleManage/maintainAttention'),
        meta: { title: '维护关注', icon: 'form' }
      },
      {
        path: 'my-attention',
        name: 'MyAttention',
        component: () => import('@/views/scheduleManage/myAttention'),
        meta: { title: '我的关注', icon: 'form' }
      }
    ]
  },
  {
    path: '/contractor',
    component: Layout,
    name: 'contractor',
    meta: { title: '承包商', icon: 'form' },
    redirect: '/contractor/contractor-list',
    children: [
      {
        path: 'contractor-list',
        name: 'ContractorList',
        component: () => import('@/views/contractor/contractorList'),
        meta: { title: '承包商列表', icon: 'form' }
      }
    ]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
